package com.grass.cropTradingCenter.controller;

import com.grass.cropTradingCenter.common.OutputException;
import com.grass.cropTradingCenter.common.Result;
import com.grass.cropTradingCenter.common.annotation.LoginFree;
import com.grass.cropTradingCenter.service.EmailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;


@RestController
@RequestMapping("/test")
@Api(tags = "测试接口")
public class TestController {

    @Autowired
    StringRedisTemplate redisTemplate;

    @Autowired
    EmailService emailService;

    @Autowired
    RedissonClient redissonClient;


    @LoginFree
    @ApiOperation("说hello")
    @GetMapping("/hello")
    public Result<String> hello(){
//        redisTemplate.opsForValue().set("k1", "v1");
//        System.out.println(redisTemplate.opsForValue().get("k1"));
        return Result.success("helloWorld");
    }


//    @LoginFree
    @ApiOperation("测试邮箱")
    @GetMapping("/test/email")
    public Result<String> testEmail(){
        emailService.sendCode("201582234@qq.com");
        return Result.success("成功了");
    }


    @LoginFree
    @ApiOperation("失败")
    @GetMapping("/error")
    public Result<String> error(){
        throw new OutputException("居然失败了");
    }


}
